package com.example.huanxin.more;

import java.util.Map;

import android.content.Context;
import android.widget.ImageView;

import com.boyuan.huijiaoyu.ColorHolderApplication;
import com.boyuan.huijiaoyu.R;
import com.squareup.picasso.Picasso;

public class UserUtils {
    /**
     * ??????username????????????user?????????demo????????????????????????????????????????????????????????????
     * @param username
     * @return
     */
    public static User2 getUserInfo(String username){
    	ColorHolderApplication instance = ColorHolderApplication.getInstance();
    	Map<String, User2> contactList = instance.getContactList();
    	User2 user = null;
    	if(contactList != null){
    		user = contactList.get(username);
    	}
    	if(user == null){
    		user = new User2(username);
    	}
    	
    	if(user != null){
    		//demo?????????????????????????????????
    		user.setNick(username);
//            user.setAvatar("http://downloads.easemob.com/downloads/57.png");
    	}
    	return user;
    }
    
    /**
     * ??????????????????
     * @param username
     */
    public static void setUserAvatar(Context context, String username, ImageView imageView){
    	User2 user = getUserInfo(username);
        if(user != null){
            Picasso.with(context).load(user.getAvatar()).placeholder(R.drawable.default_avatar).into(imageView);
        }else{
            Picasso.with(context).load(R.drawable.default_avatar).into(imageView);
        }
    }
    
}
